package com.dycx.user.converter;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dycx.user.dto.VehicleTypeSeatDTO;
import com.dycx.user.entity.VehicleTypeSeatDO;
import com.dycx.user.enums.SaleTicketTypeEnum;
import com.dycx.user.enums.SeatStatusEnum;
import com.dycx.user.vo.VehicleTypeSeatVO;
import lombok.Data;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * 车型座位表(CarTypeSeat)实体转换类
 *
 * @author wuzongbin
 * @since 2024-12-17 15:46:09
 */


@Data
public class VehicleTypeSeatConverter implements Serializable {
    public static VehicleTypeSeatDO dtoToEntity(VehicleTypeSeatDTO dto) {
        if (dto == null) return null;
        VehicleTypeSeatDO entity = BeanUtil.toBean(dto, VehicleTypeSeatDO.class);
        return entity;
    }

    public static VehicleTypeSeatVO entityToVo(VehicleTypeSeatDO entity) {
        if (entity == null) return null;
        VehicleTypeSeatVO vo = BeanUtil.toBean(entity, VehicleTypeSeatVO.class);

        SeatStatusEnum statusObj = SeatStatusEnum.converter(vo.getStatus());
        vo.setStatusName(statusObj.getName());
        vo.setStatusStyle(statusObj.getStyle());

        SaleTicketTypeEnum saleTicketTypeObj = SaleTicketTypeEnum.converter(vo.getSaleTicketType());
        vo.setSaleTicketTypeName(saleTicketTypeObj.getName());
        vo.setSaleTicketTypeStyle(saleTicketTypeObj.getStyle());

        return vo;
    }

    public static List<VehicleTypeSeatVO> entityToVoList(List<VehicleTypeSeatDO> entityList) {
        List<VehicleTypeSeatVO> voList = new ArrayList<>();
        for (VehicleTypeSeatDO entity : entityList) {
            voList.add(entityToVo(entity));
        }
        return voList;
    }

    public static Page<VehicleTypeSeatVO> entityToVoPage(Page<VehicleTypeSeatDO> page) {

        List<VehicleTypeSeatVO> newRecords = new ArrayList<>();

        List<VehicleTypeSeatDO> records = page.getRecords();
        for (VehicleTypeSeatDO entity : records) {
            newRecords.add(entityToVo(entity));
        }

        Page<VehicleTypeSeatVO> voPage = new Page<>();
        voPage.setRecords(newRecords);
        voPage.setPages(page.getPages());
        voPage.setTotal(page.getTotal());
        voPage.setSize(page.getSize());
        voPage.setCurrent(page.getCurrent());

        return voPage;
    }

}
